#ifndef _PT_SURFACE_H_
#define _PT_SURFACE_H_

typedef struct ptgui_surface
{
	void *backend;
	pt_uint32_t	refs;
} ptgui_surface_t;

extern ptgui_surface_t * ptgui_surface_get_video_surface(void);
extern void ptgui_surface_update_rects(ptgui_surface_t *surface, pt_uint32_t numrects, ptgui_rect_t *rects);
extern void ptgui_surface_update_rect(ptgui_surface_t *surface, pt_int32_t x, pt_int32_t y, pt_uint32_t w, pt_uint32_t h);
extern pt_int32_t ptgui_surface_flip(ptgui_surface_t *surface);

extern pt_uint32_t ptgui_surface_map_color
			(ptgui_surface_t *surface, pt_uint8_t r, pt_uint8_t g, pt_uint8_t b);
extern void ptgui_surface_unmap_color(pt_uint32_t pixel,
                         ptgui_surface_t *surface, pt_uint8_t *r, pt_uint8_t *g, pt_uint8_t *b);

extern ptgui_surface_t *ptgui_surface_create
			(pt_uint32_t flags, pt_int32_t width, pt_int32_t height, pt_int32_t depth, 
			pt_uint32_t Rmask, pt_uint32_t Gmask, pt_uint32_t Bmask, pt_uint32_t Amask);
extern ptgui_surface_t *ptgui_surface_create_from_data(void *pixels,
			pt_int32_t width, pt_int32_t height, pt_int32_t depth, pt_int32_t pitch,
			pt_uint32_t Rmask, pt_uint32_t Gmask, pt_uint32_t Bmask, pt_uint32_t Amask);
extern ptgui_surface_t * ptgui_surface_create_from_file(const char *src);
extern pt_int32_t ptgui_surface_save_to_file(ptgui_surface_t *surface, const char *dst);

extern void ptgui_surface_free(ptgui_surface_t *surface);

extern pt_int32_t ptgui_surface_lock(ptgui_surface_t *surface);
extern void ptgui_surface_unlock(ptgui_surface_t *surface);

extern pt_int32_t ptgui_surface_set_color_key
			(ptgui_surface_t *surface, pt_uint32_t flag, pt_uint32_t key);
extern pt_int32_t ptgui_surface_set_alpha(ptgui_surface_t *surface, pt_uint32_t flag, pt_uint8_t alpha);

extern void ptgui_surface_set_clipping(ptgui_surface_t *surface,
				pt_int32_t top, pt_int32_t left, pt_int32_t bottom, pt_int32_t right);
extern pt_int32_t ptgui_surface_fill_rect
		(ptgui_surface_t *dst, ptgui_rect_t *dstrect, pt_uint32_t color);

extern pt_uint16_t ptgui_surface_get_width (ptgui_surface_t *surface);
extern pt_uint16_t ptgui_surface_get_height (ptgui_surface_t *surface);

extern int ptgui_surface_blit
			(ptgui_surface_t *src, ptgui_rect_t *srcrect,
			 ptgui_surface_t *dst, ptgui_rect_t *dstrect);
extern void ptgui_surface_draw_pixel(ptgui_surface_t *surface,
                     pt_int16_t x, pt_int16_t y, pt_uint32_t color);
extern void ptgui_surface_draw_line(ptgui_surface_t *surface,
                    pt_uint16_t x1, pt_uint16_t y1, pt_uint16_t x2, pt_uint16_t y2,
                    pt_uint32_t color);

extern void ptgui_surface_draw_circle(ptgui_surface_t *surface,
                      pt_int16_t x0, pt_int16_t y0, pt_uint16_t r,
                      pt_uint32_t color);
extern void ptgui_surface_draw_fill_circle(ptgui_surface_t *surface,
                          pt_int16_t x0, pt_int16_t y0, pt_uint16_t r,
                          pt_uint32_t color);
extern void ptgui_surface_draw_HLine(ptgui_surface_t *surface,
                     pt_int16_t x0,pt_int16_t y0, pt_int16_t x1,
                     pt_uint32_t color);
extern void ptgui_surface_DrawVLine(ptgui_surface_t *surface,
                     pt_int16_t x0,pt_int16_t y0, pt_int16_t y1,
                     pt_uint32_t color);
extern void ptgui_surface_DrawRect(ptgui_surface_t *surface,
                    pt_int16_t x,pt_int16_t y, pt_uint16_t w,pt_uint16_t h,
                    pt_uint32_t color);
/* We wrap SDL_FillRect with the SDL_draw name convention */
#define ptgui_surface_DrawFillRect(surface, X, Y, W, H, COLOR) \
  do {                                          \
    SDL_Rect r = {(X), (Y), (W), (H)};          \
    SDL_FillRect((surface), &r, (COLOR));         \
  }while(0)
extern void ptgui_surface_DrawEllipse(ptgui_surface_t *surface,
                       pt_int16_t x0, pt_int16_t y0,
                       pt_uint16_t Xradius, pt_uint16_t Yradius,
                       pt_uint32_t color);
extern void ptgui_surface_DrawFillEllipse(ptgui_surface_t *surface,
                           pt_int16_t x0, pt_int16_t y0,
                           pt_uint16_t Xradius, pt_uint16_t Yradius,
                           pt_uint32_t color);
extern void ptgui_surface_DrawRound(ptgui_surface_t *surface,
                     pt_int16_t x0,pt_int16_t y0, pt_uint16_t w,pt_uint16_t h,
                     pt_uint16_t corner, pt_uint32_t color);
extern void ptgui_surface_DrawFillRound(ptgui_surface_t *surface,
                         pt_int16_t x0,pt_int16_t y0, pt_uint16_t w,pt_uint16_t h,
                         pt_uint16_t corner, pt_uint32_t color);

extern char *ptgui_surface_get_error (void);

#endif